﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WPFStudy.View
{
    /// <summary>
    /// AnimationBaseWindow.xaml 的交互逻辑
    /// </summary>
    public partial class AnimationBaseWindow : Window
    {
        public AnimationBaseWindow()
        {
            InitializeComponent();
        }

        private void btnDoubleAnimation_Click(object sender, RoutedEventArgs e)
        {
            DoubleAnimation doubleAnimation = new DoubleAnimation();
            doubleAnimation.Duration = TimeSpan.FromSeconds(2);
            doubleAnimation.From = 450;
            doubleAnimation.To = 420;
            doubleAnimation.AutoReverse = true;
            doubleAnimation.RepeatBehavior = RepeatBehavior.Forever;

            btnDoubleAnimation.BeginAnimation(Button.WidthProperty, doubleAnimation);
            doubleAnimation.Completed += DoubleAnimation_Completed;
        }

        private void DoubleAnimation_Completed(object? sender, EventArgs e)
        {
            //由于动画设置了 RepeatBehavior = RepeatBehavior.Forever;该回调并不会执行
            btnDoubleAnimation.Content = "动画已执行";
        }
    }
}
